package com.ukao.steward.adapter;

import android.content.Context;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ukao.steward.R;
import com.ukao.steward.base.ListBaseAdapter;
import com.ukao.steward.base.SuperViewHolder;
import com.ukao.steward.bean.ScanCodeTabBean;
import com.ukao.steward.bean.SearchUserBean;
import com.ukao.steward.util.CheckUtils;
import com.ukao.steward.util.SpanUtils;

import java.util.List;

import butterknife.BindView;


import static com.ukao.steward.R.id.phone;
import static com.ukao.steward.R.id.regionalDesc;


public class ScanCodeAdapter extends ListBaseAdapter<ScanCodeTabBean.ListBean> {


private  boolean isEnterFactory;

    public ScanCodeAdapter(Context context, List<ScanCodeTabBean.ListBean> mHomeBean,boolean isEnterFactory  ) {
        super(context, mHomeBean);
        this.isEnterFactory=isEnterFactory;
    }

    @Override
    public int getLayoutId() {
        return R.layout.adapter_scan_code;
    }

    @Override
    public void onBindItemHolder(SuperViewHolder holder, int position) {
        TextView orderNo = holder.getView(R.id.orderNo);
        TextView transNo = holder.getView(R.id.transNo);
        TextView proCnt = holder.getView(R.id.proCnt);
        LinearLayout orderNolayout = holder.getView(R.id.orderNo_layout);
        LinearLayout transNolayout = holder.getView(R.id.transNo_layout);
        LinearLayout factoryTransNolayout = holder.getView(R.id.factoryTransNo_layout);
        TextView factoryTransNo = holder.getView(R.id.factoryTransNo);

        LinearLayout mlayout = holder.getView(R.id.layout);
        ScanCodeTabBean.ListBean    item= mDataList.get(position);

        if (CheckUtils.isEmpty(item.getOrderNo())){
            orderNolayout.setVisibility(View.GONE);

        }else{
            orderNolayout.setVisibility(View.VISIBLE);
                   orderNo.setText(item.getOrderNo());

        }

        if (CheckUtils.isEmpty(item.getTransNo())||!isEnterFactory){
            transNolayout.setVisibility(View.GONE);
        }else{
            transNolayout.setVisibility(View.VISIBLE);

                   transNo.setText(item.getTransNo());
        }

        if (CheckUtils.isEmpty(item.getFactoryTransNo())||!isEnterFactory||isEnterFactory){
            factoryTransNolayout.setVisibility(View.GONE);
        }else{
            factoryTransNolayout.setVisibility(View.VISIBLE);
            factoryTransNo.setText(item.getFactoryTransNo());
        }


        int  total=item.getProCnt()+item.getAnnexCnt();
        mlayout.setBackgroundColor(getColors(R.color.back_40));
//        if (position==0){
//            mlayout.setBackgroundColor(getColors(R.color.back_40));
//        }else{
//            mlayout.setBackgroundColor(getColors(R.color.white26));
//        }

        if (total!=0){
            CharSequence  mCharSequence=new SpanUtils().append(total+"").append("-"+item.getProCnt()+"/"+item.getAnnexCnt()).
                    setForegroundColor(getColors(R.color.white)).create();
            proCnt.setText(mCharSequence);
        }else{
            proCnt.setText("");
        }


    }
}
